package com.test.service;

import com.test.entry.Order;
import com.test.utils.MysqlUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class OrderService {


    public void insert(Order order) {
        Connection connection = MysqlUtils.getConnection();
        Statement stat = null;
        try {
            stat = connection.createStatement();

            String sql = "insert into t_order(name,code,account_no)value(" + getValue(order.getName()) + "," + getValue(order.getCode()) + "," + getValue(order.getAccountNo()) + ")";

            System.out.println(sql);
            int count = stat.executeUpdate(sql);
            System.out.println("影响行数 " + count);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            MysqlUtils.release(connection, stat, null);
        }
    }

    private String getValue(Object v) {
        return "'" + v + "'";
    }

   /* public static void main(String[] args) {
        Order order=new Order();
        order.setAccountNo("z");
        order.setCode("z");
        order.setName("z");
        String sql = "insert into t_order(name,code,account_no)value(" + getValue(order.getName()) + "," + getValue(order.getCode()) + "," + getValue(order.getAccountNo())+")";
        System.out.println(sql);
    }*/
}
